package com.jinzihan.dao.impl;

import com.jinzihan.dao.ClassroomDao;
import com.jinzihan.entity.Classroom;

import java.util.List;

public class ClassroomDaoImpl extends BaseDao implements ClassroomDao {
    @Override
    public int saveClassroom(Classroom classroom) {
        String sql = "INSERT INTO t_classroom(NAME,capacity,MEDIUM,TYPE,STATUS) VALUES(?,?,?,?,?)";
        return update(sql,classroom.getName(),classroom.getCapacity(),classroom.getMedium(),classroom.getType(),classroom.getStatus());
    }

    @Override
    public int changeClassroomStatus(int id,Integer status) {
        String sql = "update t_classroom set status=? where id=?";
        return update(sql,status,id);
    }

    @Override
    public List<Classroom> queryAllClassrooms() {
        String sql = "select id,name,capacity,medium,type,status from t_classroom";
        return queryForList(Classroom.class,sql);
    }

    @Override
    public int updateClassroom(Classroom classroom) {
        String sql = "update t_classroom set name=?,capacity=?,medium=?,type=?,status=? where id=?";
        return update(sql,classroom.getName(),classroom.getCapacity(),classroom.getMedium(),classroom.getType(),classroom.getStatus(),classroom.getId());
    }

    @Override
    public Classroom queryClassroomById(int id) {
        String sql = "select id,name,capacity,medium,type,status from t_classroom where id = ?";
        return queryForOne(Classroom.class,sql,id);
    }

    @Override
    public int queryForClassroomCount() {
        String sql = "select count(*) from t_classroom";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public int deleteClassroomById(int id) {
        String sql = "delete from t_classroom where id = ?";
        return update(sql,id);
    }

    @Override
    public List<Classroom> queryForPageItems(int begin,int pageSize) {
        String sql = "select id,name,capacity,medium,type,status from t_classroom limit ?,?";
        return queryForList(Classroom.class,sql,begin,pageSize);
    }
}
